home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / others / ngz.zip / NGZ.GLO < prev    next >
Text File  |  1993-05-14  |  15KB  |  339 lines

  1.  
  2.  
  3. { NGZ.GLO  ---  Global definitions for NGZ.PAS }
  4.  
  5.  
  6. { Contents: CONST, TYPE, and VAR for NGZ
  7.             Note on NG v1.0 database file format (structures)
  8.             Note on NG disassembly
  9. }
  10.  
  11.  
  12. { MIN & MAX --------------------------------------------------------------- }
  13.  
  14. { Most of these CONSTs have their origin in the NG documentation }
  15.  
  16. CONST
  17.    name_len             =   40;   { max. length of database name }
  18.    credits_str_len      =   65;   { max. length of credits strings }
  19.    credits_num          =    5;   { max. no. of credits strings }
  20.    max_menus            =   10;   { max. no. of (horizontal) menus }
  21.    max_items            =    8;   { max. no. of items per menu (less title) }
  22.    short_str_len        =   78;   { max. displayed length of 'short entry'
  23.                                     string, does not include attrib signs }
  24.    long_str_len         =   78;   { max. displayed length of 'long entry'
  25.                                     string, does not include attrib signs }
  26.  
  27.    long_struc_size_max  = 17 * 1024;  { 17 KB is max. size for a long entry
  28.                                         in source format }
  29.    header_size          =  378;   { file offset 0..377 }
  30.    NG_file_signature    = 'NG';   { yeah }
  31.  
  32.  
  33.    { The caret (^) denotes that the following char has special meaning,
  34.      i.e. attribute byte or character drawing byte. The caret itself
  35.      therefore appears as two (^^).
  36.      Attributes are in effect until changed by another, or until end of
  37.      screen line.
  38.    }
  39.    caret                =  '^';
  40.    bold                 = '^b';
  41.    underline            = '^u';
  42.    reverse              = '^r';
  43.    normal               = '^n';
  44.    attrib               = '^A';   { format: ^Axx where xx is hex number }
  45.    charac               = '^C';   { format: ^Cxx where xx is hex number }
  46.  
  47.    null                 =   #0;   { ASCIIZ strings are null-terminated }
  48.    reserved_char        = #255;   { byte following #255 denotes number of
  49.                                     blanks (#32) to expand }
  50.  
  51.  
  52.    crypto               =  $1A;   { except for file header, ALL file bytes
  53.                                     are encrypted }
  54.    fixed_struc_size     =  $1A;   
  55.  
  56.  
  57. CONST
  58.    short_ID     = 0;
  59.    long_ID      = 1;
  60.    menu_ID      = 2;
  61.  
  62.  
  63. { FILE HANDLING ----------------------------------------------------------- }
  64.  
  65. TYPE
  66.    DWORD  = Longint;
  67.  
  68. TYPE
  69.    bigbuf = ARRAY[0..long_struc_size_max - 1 + $1A] OF BYTE;  { 17 KB }
  70.    str79  = STRING[79];
  71.  
  72. VAR
  73.    in_name         : str79;                 { input filename }
  74.    dir_info        : Dos.SearchRec;         { used with FindFirst }
  75.    NGf             : FILE;                  { input NG database file }
  76.    linkf           : TEXT;                  { output link control file }
  77.    makef           : TEXT;                  { output MAKE file }
  78.    reptf           : TEXT;                  { report file }
  79.    screen          : TEXT;                  { CON }
  80.    datf            : TEXT;                  { output data file }
  81.    buf             : bigbuf;                { buffer to hold one struc }
  82.    sbuf            : bigbuf;                { buffer to hold short struc while
  83.                                               writing longs }
  84.    textbuffer      : ARRAY[0..8191] OF BYTE;{ for faster writes }
  85.    varia_struc_size: WORD;                  { size of struc's var. portion }
  86.    fprefix         : STRING[4];    { used for naming output files }
  87.    out_files_num   : WORD;         { count output data files (one-based) }
  88.    last_read_pos   : DWORD;        { file offs. of last struc read }
  89.  
  90.  
  91. CONST
  92.    dot_NGO  = '.NGO';  { reserved .ext for NG object files }
  93.    dot_NG   = '.NG' ;  { do. , NG database files }
  94.    dot_ASC  = '.ASC';  { output data files (ascii) }
  95.    dot_LCF  = '.LCF';  { link control file }
  96.    dot_MAK  = '.MAK';  { make file }
  97.    dot_RPT  = '.RPT';  { report file }
  98.    _112     =    112;  { partial disassembly file no. }
  99.    { output file names:
  100.      data   : NAMEnnn.ASC     nnn = count (VAR out_files_num)
  101.      linkf  : NAME.LCF        NAME = first four letters of input file name
  102.      makef  : NAME.MAK
  103.      reptf  : NAME.RPT
  104.    }
  105.  
  106.  
  107. { PROGRAM FLOW & STRINGS -------------------------------------------------- }
  108.  
  109. CONST
  110.    crlf   = #13#10;
  111.    one_hundred = 78+22+40;   { expanded NG strings: add space for
  112.                                attribute signs }
  113. TYPE
  114.    str40  = STRING[name_len];
  115.    str65  = STRING[credits_str_len];
  116.    str78  = STRING[long_str_len];
  117.    str100 = STRING[one_hundred];
  118.    str12  = STRING[12];
  119.    str8   = STRING[8];
  120.    str4   = STRING[4];
  121.    str3   = STRING[3];
  122.    str2   = STRING[2];
  123.    str127 = STRING[127];
  124.  
  125. TYPE
  126.    drop_menu    = RECORD  { vertical menu }
  127.                      txt  : str40;   { menu item text }
  128.                      fptr : DWORD;   { file ptr to struc }
  129.                      datn : WORD;    { corresponding data file number }
  130.                   END;
  131.    top_menu     = RECORD  { horizontal menu }
  132.                      toptxt : str40;
  133.                      items  : WORD;  { no. of items in drop menu }
  134.                      drop   : ARRAY[0..max_items -1] OF drop_menu;
  135.                   END;
  136. TYPE
  137.    struc_rec_ptr = ^struc_rec;
  138.    struc_rec    = RECORD      { list of strucs that go in separate files }
  139.                      ID        : WORD;
  140.                      file_offs : DWORD;
  141.                      par_ptr   : DWORD;
  142.                      first_ptr : DWORD;
  143.                      last_ptr  : DWORD;
  144.                      tgt_file  : WORD;
  145.                      txt       : STRING[55];  { subject text }
  146.                      next      : struc_rec_ptr;
  147.                   END;
  148.                   { At 80 bytes/rec, NGZ will run out of memory only if the
  149.                     NGuide has a humongous size }
  150.  
  151. VAR
  152.    rc           : BYTE;    { return code }
  153.    cmd          : str127;  { command line }
  154.    is_info_req  : BOOLEAN; { cmd. line switches }
  155.    is_quiet     : BOOLEAN;
  156.    is_rept_only : BOOLEAN;
  157.    is_partial   : BOOLEAN;
  158.    partial_offs : DWORD;
  159.  
  160.    NG_name      : str40;
  161.    credits      : ARRAY[0..credits_num - 1] OF str65;
  162.    last_ID      : WORD;  { ID of last read struc }
  163.    menu         : ARRAY[0..max_menus - 1] OF top_menu;
  164.    no_of_menus  : WORD;  { one-based }
  165.    no_of_shorts : WORD;  { for statistics }
  166.    no_of_longs  : DWORD; { for statistics }
  167.    file_size    : DWORD; { size of NGf }
  168.    curr_menu    : WORD;
  169.    curr_item    : WORD;
  170.  
  171.    srm,sra,                        { Mark, aux, }
  172.    sr1,srp,src  : struc_rec_ptr;   { 1st, previous, current }
  173.  
  174.  
  175. (*
  176. ------------------------------------------------------------------------------
  177. NG v1.0 DATABASE FILE FORMAT (STRUCTURES)
  178.  
  179.           An NG database file consists of a header plus a sequence of
  180.           data structures. Each data structure has a portion of fixed
  181.           size, and a portion of variable size.
  182.  
  183.           There are three data structures:
  184.              1) Menu struc   - all are located after file header
  185.                                expands into 2) or 3)
  186.              2) Short struc  - expands into 2) and/or 3) or is void
  187.              3) Long struc   - includes seealso data struc, if appr.
  188.  
  189.           There is no limit to how deep short structures can be nested
  190.           (using the !File keyword).
  191.  
  192.  
  193. Note: All offsets are zero-based
  194. ------------------------------------------------------------------------------
  195. Header structure        (Size = 378 = $17A bytes)
  196. ARRAY[0..1] OF BYTE     NG signature ('NG')
  197. WORD                    [?? Always zero]
  198. WORD                    [?? Always 1, probably NG version (1.0)]
  199. WORD                    Number of menu structures in database file
  200. ARRAY[8..47] OF BYTE    Guide name (asciiz)
  201. ARRAY[48..377] OF BYTE  Credits strings (asciiz), 5 * (65+1)
  202. ------------------------------------------------------------------------------
  203. Menu structure (fixed part)  (Size = 26 = $1A bytes)
  204. WORD    ID              Menu_ID = 2
  205. WORD    Var_sz          Byte size of this menu's variable part (incl. trailing
  206.                         zero)
  207. WORD    Items           Number of menu items incl. menu title
  208. WORD    Ptr_sz          [= 4 * (Items - 1) ; indirect ptr to menu title str?]
  209. ARRAY[8..25] OF BYTE    [?? Always zero, probably unused]
  210. ------------------------
  211. Menu structure (variable part)
  212. ARRAY[Items-1] OF DWORD File ptr; a menu expands into a long or short struc
  213. ARRAY[Items] OF RECORD
  214.    WORD                 Offset of menu item string into variable part;
  215.                         1st -> 1st item str., last -> 0, menu title string
  216.                         is not pointed to (located before 1st item string)
  217.    ARRAY[6] OF BYTE     [?? Always zero, probably unused]
  218.    END;
  219. ARRAY[Items][X] OF BYTE Items * asciiz strings
  220. BYTE                    Trailing zero byte
  221. ------------------------------------------------------------------------------
  222. Short structure (fixed part) (Size = 26 = $1A bytes)              (Hex offset)
  223. WORD    ID              Short_ID = 0                                   ( $00 )
  224. WORD    Var_sz          Byte size of this short struc's variable part  ( $02 )
  225. WORD    Items           Number of items in short list                  ( $04 )
  226. WORD                    [?? Always zero, probably unused]              ( $06 )
  227. WORD                    Denotes that this struc is item # in parent's list
  228.                         (pressing Esc...), -1 if no parent             ( $08 )
  229. DWORD                   File pointer to parent struc, -1 if no parent  ( $0A )
  230. WORD                    Struc belongs to menu #                        ( $0E )
  231. WORD                    Struc belongs to menu item #                   ( $10 )
  232. ARRAY[18..25] OF BYTE   [?? Always zero, probably unused]              ( $12 )
  233. ------------------------
  234. Short structure (variable part)
  235. ARRAY[Items] OF RECORD
  236.    WORD                 Offset of short entry string into variable part
  237.    DWORD                File ptr; points to a long struc, to another short
  238.                         struc, or to nothing, -1 if nothing
  239.    END;
  240. ARRAY[Items][X] OF BYTE Items * asciiz strings
  241. ------------------------------------------------------------------------------
  242. Long structure (fixed part)  (Size = 26 = $1A bytes)              (Hex offset)
  243. WORD    ID              Long_ID = 1                                    ( $00 )
  244. WORD    Var_sz          Byte size of this long struc's variable part, incl.
  245.                         seealso data, if any                           ( $02 )
  246. WORD    Lines           Number of lines in long entry                  ( $04 )
  247. WORD    SA_offs         Offset of seealso struc into variable part ;   ( $06 )
  248.                         zero if no seealso data
  249. WORD                    Denotes that this struc is item # in parent's list,
  250.                         -1 if no parent                                ( $08 )
  251. DWORD                   File ptr to parent struc, if any; -1 if no par.( $0A )
  252. WORD                    Struc belongs to menu #                        ( $0E )
  253. WORD                    Struc belongs to menu item #                   ( $10 )
  254. DWORD                   File ptr to previous long, -1 if N/A           ( $12 )
  255. DWORD                   File ptr to next long, -1 if N/A               ( $16 )
  256. ------------------------
  257. Long structure (variable part)
  258. ARRAY[Lines][X] OF BYTE Lines * asciiz strings
  259.    ---------------------------------------------------------------------------
  260.    Note: The seealso structure always appears as a part of a long structure.
  261.          It is void if long's SA_offs = zero.
  262.  
  263.    Seealso structure (fixed part) (Size = 2 bytes)
  264.    WORD    SA_no           Number of seealso entries
  265.    ------------------------
  266.    Seealso structure (variable part)
  267.    ARRAY[SA_no] OF DWORD   File ptr to cross ref. entry (a long struc)
  268.    ARRAY[SA_no][X] OF BYTE SA_no * asciiz strings
  269.    BYTE                    Trailing zero byte
  270. ------------------------------------------------------------------------------
  271.  
  272. Notes:  ASCIIZ = ordinary (ascii) text string terminated by zero (chr(0)).
  273.  
  274.         NG has a simple string compression method: If $FF (=chr(255)) appears
  275.         in a text string, the following byte denotes how many blanks (chr(32))
  276.         to insert. A $FF will compile as a $FF, though. One example of a text
  277.         string ending in a double $FF (?).
  278.  
  279.         DIS_NG and NGDUMP operate with an End_ID = 5; I haven't seen one...
  280.         however, I have come across NGs filled (at eof) with zeros (i.e.
  281.         after decryption) to a 128-byte boundary.
  282.  
  283.         Fields not accounted for (marked '??'): I think it's safe to assume
  284.         that these are place holders, at least those appearing in the fixed
  285.         part of the structures since only the long struc uses all 26 bytes.
  286.  
  287.         Recompiled NG size differs from original: Right...Not too sure, but
  288.         it probably has to do with the space (de-)compression.
  289. *)
  290.  
  291. (* ---------------------------------------------------------------------------
  292.  
  293.    NG DISASSEMBLY:
  294.  
  295.    1) Process header
  296.    2) ..and menus
  297.    3) In order to:
  298.          a) build !File refs (point to another short)
  299.          b) resolve S/A refs (point to a long) and link these to a
  300.             filename, if appropriate
  301.  
  302.       the program must:
  303.          A) register all strucs that go in separate files, i.e. all short
  304.             strucs, and long strucs with no parent (off the menu), and in
  305.             the process make a note of the interval (1st and last long)
  306.             referenced by an end-of-chain short struc
  307.             (this is done by reading all struc headers in NG file sequenti-
  308.              ally and chaining these to a parent, if any)
  309.  
  310.          B) for strucs found under A) build the following information:
  311.             a) W   ID           ID of this struc (gotta be 0 or 1)
  312.             b) DW  FileOffs     starting file offset of this struc
  313.             c) DW  FirstPtr     ptr to 1st long (if end-of-chain short struc)
  314.             d) DW  LastPtr      ptr to last long (if end-of-chain short struc)
  315.                                 for an off-the-menu long struc: b = c) = d)
  316.                                 for a has-parent short struc: c) & d) = N/A
  317.             e) W   TgtFile      filename this struc will go in (stored as
  318.                                 number)
  319.             f) DW  next         pointer to next struc record (single-linked
  320.                                 list)
  321.             g) DW  ParPtr       pointer to parent, -1 if no parent
  322.  
  323.    4)  Write data files by processing all strucs in pointer list, i.e.
  324.        current struc and its child, if any; !File and !Seealso references
  325.        are resolved by a pointer table lookup
  326.  
  327.    5)  Write link and make file to use with NGML.EXE and MAKE.EXE
  328.        Write report file (file index, unresolved seealsos et al.)
  329.  
  330.  
  331.    May, 1993
  332.    Morten Elling
  333.    DK-8000 Aarhus C.
  334.  
  335. *)
  336.  
  337. { eof }
  338.  
  339.